import static org.junit.Assert.*;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import android.util.Log;

import com.wirelesstransfer.server.ConnectedClients.ConnectedClient;


public class TestConnectedClient {

	String ip1 = "1.1";
	String id1 = "1";
	List<File> list;
	
	File f1 = new File("f1");
	File f2 = new File("f2");
	File f3 = new File("f3");
	
	
	@Test
	public void testRemaningFile() {
		list = new ArrayList<File>();
		list.add(f1);
		list.add(f2);
		
		ConnectedClient c1 = new ConnectedClient(ip1, id1, list);
		c1.nextFile();
		list.remove(f1);
		assertTrue(list.equals(c1.getRemainingFiles()));
	}

	@Test
	public void testGetReceivedFiles() {
		list = new ArrayList<File>();
		list.add(f1);
		ConnectedClient c1 = new ConnectedClient(ip1, id1, list);
		c1.nextFile();
		c1.nextFile();
		assertEquals(list.toString(), c1.getFiles().toString());
	}

	@Test
	public void testGetCurrentFile() {
		list = new ArrayList<File>();
		list.add(f1);
		list.add(f2);
		ConnectedClient c1 = new ConnectedClient(ip1, id1, list);
		c1.nextFile();
		c1.nextFile();
		assertTrue(list.get(1).equals(c1.getCurrentFile()));	
		}


	@Test
	public void testNextFile() {
		list = new ArrayList<File>();
		list.add(f1);
		list.add(f2);
		list.add(f3);
		ConnectedClient c1 = new ConnectedClient(ip1, id1, list);
		assertTrue(list.equals(c1.getRemainingFiles()));
		assertTrue(c1.getCurrentFile() == null);
		assertTrue(c1.getReceivedFiles() == null);
		
		c1.nextFile();
		
		List<File> exp = new ArrayList<File>();
		exp.add(f2);
		exp.add(f3);
		
		assertEquals(c1.getRemainingFiles(), exp);
		assertTrue(c1.getCurrentFile().equals(list.get(0)));
		assertTrue(c1.getReceivedFiles() == null);

		c1.nextFile();
		
		exp.remove(f2);
		
		List<File> exp1 = new ArrayList<File>();
		exp1.add(f1);

		assertEquals(c1.getRemainingFiles(), exp);
		assertTrue(c1.getCurrentFile().equals(list.get(1)));
		System.err.println(c1.getReceivedFiles().toString());
		assertEquals(c1.getReceivedFiles(), exp1);
		
		c1.nextFile();
		
		exp.remove(f3);
		
		exp1.add(f2);

		assertEquals(c1.getRemainingFiles(), null);
		assertTrue(c1.getCurrentFile().equals(list.get(2)));
		System.err.println(c1.getReceivedFiles().toString());
		assertEquals(c1.getReceivedFiles(), exp1);
		
		c1.nextFile();
				
		exp1.add(f3);

		assertEquals(c1.getRemainingFiles(), null);
		assertTrue(c1.getCurrentFile()==null);
		System.err.println(c1.getReceivedFiles().toString());
		assertEquals(c1.getReceivedFiles(), exp1);
	}
}
